<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>手写深度比较</title>
</head>
<body>
  <script>
    var obj1 = {
      a: 100,
      b: 200,
      c: {
        x: 200,
        y: 100
      }
    }
    var obj2 = {
      a: 100,
      b: 200,
     
    }
    //  判断是否为对象
    function isObject(obj) {
      return typeof obj === 'object'&& obj !== null
    }
    function isEqual(obj1,obj2) {
      if(!isObject(obj1) || !isObject(obj2)) {
        return obj1 === obj2
      }
      let obj1Keys = Object.keys(obj1)
      let obj2Keys = Object.keys(obj2)
      if(obj1Keys.length !== obj2Keys.length) {
        return false
      }
      for(key in obj1) {
        let res = isEqual(obj1[key], obj2[key])
        if(!res) {
          return false
        }
      }
      return true
    }
  </script>
</body>
</html>